//顯示｜隱藏詳細訊息
function con_detail_info(){	
	var div = $("#detail_info");
	var dis = div.css('display');
	if(dis == 'none'){ div.show(); }else{ div.hide(); }
}

function checkform2(){
	var check=$(".check").get();
	var error=0;
	$.each(check,function(key,value){
		$(this).css("border","");
		$(this).attr("title","");
		if(value["value"]===''){
			$(this).attr("title","這裡不能為空");
			error++;
		}
	});	
	if(error===0){
		//$(".tips").html("<span style='font-size:30px;color:green;'>√</span>");
		$("#userinfo").submit();
	}else{
		//$(".tips").html("<span style='font-size:30px;color:red;'>注：紅色邊框的輸入框為必填項</span>");
	}
}

//mobile start 行動電話
function checkMobile(num,value,msg){ 
	if(value != '' && value != null){ 
		if(num == 1){ addEle_Mobile1(value,msg); }
		if(num == 2){ addEle_Mobile2(value,msg); }
	}
}
function addEle_Mobile(){
	var li1 = $('#1').attr('id');
	var li2 = $('#2').attr('id');	
	var li=$('#add_tel li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 1){ addEle_Mobile1('','Y'); }
	else if(li1 == 1 && li2 != 2){ addEle_Mobile2('','Y'); }
}
function addEle_Mobile1(value,msg){
	if(msg=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'"; }	
	$("#add_tel").append("<li id='1'><input type='text' class='mobile' name='cu_mobile1' value='"+value+"'/><a onclick='removeEle_Mobile(1)' class='deleteitem'><i class='icon-trash'></i></a></li>");
	$("#mobilesms").append("<li id='1'><input type='radio' name='cu_sms1' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_sms1' value='N' "+check2+" />N</li>");
}
function addEle_Mobile2(value,msg){
	if(msg=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'";}
	$("#add_tel").append("<li id='2'><input type='text' class='mobile' name='cu_mobile2' value='"+value+"'/><a onclick='removeEle_Mobile(2)' class='deleteitem'><i class='icon-trash'></i></a></li>");
	$("#mobilesms").append("<li id='2'><input type='radio' name='cu_sms2' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_sms2' value='N' "+check2+" />N</li>");
}
function removeEle_Mobile(item){
	$("#"+item).remove();	
	$("#"+item).remove();
}
//mobile end

//home_tel start	住家電話
function checkH_tel(num,value,msg){
	if(value!=''&&value!=null){
		if(num == 1){ addEle_hometel1(value); }
		if(num == 2){ addEle_hometel2(value); }
	}
}
function addEle_hometel(){
	var li1 = $('#3').attr('id');
	var li2 = $('#4').attr('id');	
	var li=$('#home_tel li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 3){ addEle_hometel1(''); }
	else if(li1 == 3 && li2 != 4){ addEle_hometel2(''); }
}
function addEle_hometel1(value){
	$("#home_tel").append("<li id='3'><input type='text' class='colspan_input1' name='cu_htel1' value='"+value+"' /><a onclick='removeEle_hometel(3)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function addEle_hometel2(value){
	$("#home_tel").append("<li id='4'><input type='text' class='colspan_input1' name='cu_htel2' value='"+value+"' /><a onclick='removeEle_hometel(4)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function removeEle_hometel(item){ $("#"+item).remove(); }
//home_tel end

//company_tel start
function checkC_tel(num,value,fenji){
	if(value!=''&&value!=null){
		if(num == 1){ addEle_company_tel1(value,fenji); }
		if(num == 2){ addEle_company_tel2(value,fenji); }
	}
}
function addEle_company_tel(){
	var li1 = $('#5').attr('id');
	var li2 = $('#6').attr('id');	
	var li=$('#company_tel li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 5){ addEle_company_tel1('',''); }
	else if(li1 == 5 && li2 != 6){ addEle_company_tel2('',''); }
}
function addEle_company_tel1(value,fenji){
	$("#company_tel").append("<li id='5'><input type='text' class='colspan_input1' name='cu_ctel1' value='"+value+"' />&nbsp;&nbsp;<b>分機</b>&nbsp;&nbsp;<input type='text' name='cu_ext1' value='"+fenji+"' class='c_tel_2' />&nbsp;<a onclick='removeEle_company_tel(5)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function addEle_company_tel2(value,fenji){
	$("#company_tel").append("<li id='6'><input type='text' class='colspan_input1' name='cu_ctel2' value='"+value+"' />&nbsp;&nbsp;<b>分機</b>&nbsp;&nbsp;<input type='text' name='cu_ext2' value='"+fenji+"' class='c_tel_2' />&nbsp;<a onclick='removeEle_company_tel(6)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function removeEle_company_tel(item){ $("#"+item).remove(); }
//=========company_tel end

//=========email start	電子郵件
function check_email(num,value,edm){
	if(value!=''&&value!=null){
		if(num == 1){ addEle_email1(value,edm); }
		if(num == 2){ addEle_email2(value,edm); }
	}
}
function addEle_email(){
	var li1 = $('#7').attr('id');
	var li2 = $('#8').attr('id');	
	var li=$('#email li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 7){ addEle_email1('','Y'); }
	else if(li1 == 7 && li2 != 8){ addEle_email2('','Y'); }
}
function addEle_email1(value,edm){
	if(edm=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'"; }
	var radio="<input type='radio' name='cu_edm1' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_edm1' value='N' "+check2+" />N";
	$("#email").append("<li id='7'><input type='text' name='cu_mail1' id='cu_mail1' value='"+value+"' class='email_input' /><input type='button' value='開啟mail' onclick=open_email('cu_mail1')  /><a onclick='removeEle_email(7)' class='deleteitem' ><i class='icon-trash'></i></a></li>");
	$("#email_edm").append("<li id='7'>"+radio+"</li>");
}
function addEle_email2(value,edm){
	if(edm=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'"; }
	var radio="<input type='radio' name='cu_edm2' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_edm2' value='N' "+check2+" />N";
	$("#email").append("<li id='8'><input type='text' name='cu_mail2' id='cu_mail2' value='"+value+"' class='email_input' /><input type='button' value='開啟mail' onclick=open_email('cu_mail2')  /><a onclick='removeEle_email(8)' class='deleteitem' ><i class='icon-trash'></i></a></li>");
	$("#email_edm").append("<li id='8'>"+radio+"</li>");
}
function removeEle_email(item){
	$("#"+item).remove();
	$("#"+item).remove();
}
//email end

//fax start 傳真電話
function checkF_tel(num,value){
	if(value!=''&&value!=null){ 
		if(num == 1){ addEle_fax1(value); }
		if(num == 2){ addEle_fax2(value); }
	}
}
function addEle_fax(value){
	var li1 = $('#9').attr('id');
	var li2 = $('#10').attr('id');	
	var li=$('#fax li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 9){ addEle_fax1(''); }
	else if(li1 == 9 && li2 != 10){ addEle_fax2(''); }
}
function addEle_fax1(value){
	$("#fax").append("<li id='9'><input type='text' class='colspan_input1' name='cu_fax1' value='"+value+"' />&nbsp;<a onclick='removeEle_fax(9)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function addEle_fax2(value){
	$("#fax").append("<li id='10'><input type='text' class='colspan_input1' name='cu_fax2' value='"+value+"' />&nbsp;<a onclick='removeEle_fax(10)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function removeEle_fax(item){ $("#"+item).remove(); }
//fax end

//homeaddress start	住家地址
function checkH_addr(num,value,name,ispub){
	if(value!=''&&value!=null){ 
		if(num == 1){ addEle_address1(value,name,ispub); }
		if(num == 2){ addEle_address2(value,name,ispub); }
	}
}
function addEle_address(){
	var li1 = $('#11').attr('id');
	var li2 = $('#12').attr('id');	
	var li=$('#home_addr li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 11){ addEle_address1('','','Y'); }else if(li1 == 11){ addEle_address2('','','Y'); }
}
function addEle_address1(value,name,msg){
	if(msg=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'"; }
	var build_name=$("#cu_hbuild1").html();
	if(name==0){ build_name=$("#cu_hbuild_none").html(); }
	var radio="<input type='radio' name='cu_hpubl1' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_hpubl1' value='N' "+check2+" />N";
	$("#home_addr").append("<li id='11'><input type='text' class='colspan_input' name='cu_hadd1' id='cu_hadd1' value='"+value+"' onClick=showFamilyAddress('cu_hadd1'); /><a onclick='removeEle_address(11)' class='deleteitem'><i class='icon-trash'></i></a></a></li>");
	$("#building_name").append("<li class='11'><select name='cu_hbuild1' class='full_select' >"+build_name+"</select></li>");
	$("#per").append("<li class='11'>"+radio+"</li>");
}
function addEle_address2(value,name,msg){
	if(msg=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'"; }
	var build_name=$("#cu_hbuild2").html();
	if(name==0){ build_name=$("#cu_hbuild_none").html(); }
	var radio="<input type='radio' name='cu_hpubl2' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_hpubl2' value='N' "+check2+" />N";
	$("#home_addr").append("<li id='12'><input type='text' class='colspan_input' name='cu_hadd2' id='cu_hadd2' value='"+value+"' onClick=showFamilyAddress('cu_hadd2'); /><a onclick='removeEle_address(12)' class='deleteitem'><i class='icon-trash'></i></a></a></li>");
	$("#building_name").append("<li class='12'><select name='cu_hbuild2' class='full_select' >"+build_name+"</select></li>");
	$("#per").append("<li class='12'>"+radio+"</li>");
}
function removeEle_address(item){
	$("#"+item).remove();
	$("."+item).remove();
}
//homeaddress end

//company start (value 公司名稱，type 公司類型，code 統一編號，dep 部門，zhicheng 職稱，utype 類別)
function check_company(num,value,type,code,dep,zhicheng,utype){
	if(value!=''&&value!=null){ 
		if(num == 1){ addEle_company1(value,type,code,dep,zhicheng,utype); }
		if(num == 2){ addEle_company2(value,type,code,dep,zhicheng,utype); }
	}
}
function addEle_company(){
	var li1 = $('#13').attr('id');
	var li2 = $('#14').attr('id');	
	var li=$('#company_name li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 13){ addEle_company1('','','','','',''); }else if(li1 == 13){ addEle_company2('','','','','',''); }
}
function addEle_company1(value,type,code,dep,zhicheng,utype){
	var ctype=$("#cu_type1").html();
	if(type==0){ ctype=$("#cu_type_none").html(); }
	var cu_cate=$("#cu_cate1").html();
	var cu_titles=$("#cu_titles1").html();
	if(utype==undefined){ cu_cate=$("#cu_cate_none").html(); }
	if(zhicheng==undefined){ cu_titles=$('#cu_titles_none').html(); }
	$("#company_name").append("<li id='13'><input type='text' class='colspan_input' name='cu_company1' value='"+value+"' /><a onclick='removeEle_company(13)' class='deleteitem'><i class='icon-trash'></i></a></a></li>");
	$('#company_type').append("<li class='13'><select name='cu_type1' class='full_select' >"+ctype+"</select></li>");
	$("#company_id").append("<li class='13'><input type='text' name='cu_unified1' onblur='checkuniformcode(this);' value='"+code+"' /></li>");
	$("#dept").append("<li class='13'><input type='text' name='cu_dep1' value='"+dep+"' /></li>");
	$("#zhichen").append("<li class='13'><select name='cu_titles1' >"+cu_titles+"</select></li>");
	$('#company_type2').append("<li class='13'><select name='cu_cate1' class='full_select' >"+cu_cate+"</select></li>");
}
function addEle_company2(value,type,code,dep,zhicheng,utype){
	var ctype=$("#cu_type2").html();
	if(type==0){ ctype=$("#cu_type_none").html(); }
	var cu_cate=$("#cu_cate2").html();
	var cu_titles=$("#cu_titles2").html();
	if(utype==undefined){ cu_cate=$("#cu_cate_none").html(); }
	if(zhicheng==undefined){ cu_titles=$('#cu_titles_none').html(); }
	$("#company_name").append("<li id='14'><input type='text' class='colspan_input' name='cu_company2' value='"+value+"' /><a onclick='removeEle_company(14)' class='deleteitem'><i class='icon-trash'></i></a></a></li>");
	$('#company_type').append("<li class='14'><select name='cu_type2' class='full_select' >"+ctype+"</select></li>");
	$("#company_id").append("<li class='14'><input type='text' name='cu_unified2' onblur='checkuniformcode(this);' value='"+code+"' /></li>");
	$("#dept").append("<li class='14'><input type='text' name='cu_dep2' value='"+dep+"' /></li>");
	$("#zhichen").append("<li class='14'><select name='cu_titles2' >"+cu_titles+"</select></li>");
	$('#company_type2').append("<li class='14'><select name='cu_cate2' class='full_select' >"+cu_cate+"</select></li>");
}
function removeEle_company(item){
	$("#"+item).remove();
	$("."+item).remove();
}
//company end

//company_addr start （addr 公司地址，name 大樓名稱，pub 寄發刊物，website 公司網址）
function check_C_addr(num,value,build,ispub,type){
	if(value!=''&&value!=null){ 
		if(num == 1){ addEle_company_addr1(value,build,ispub,type); }
		if(num == 2){ addEle_company_addr2(value,build,ispub,type); }
	}
}
function addEle_company_addr(){
	var li1 = $('#15').attr('id');
	var li2 = $('#16').attr('id');	
	var li=$('#company_addr li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 15){ addEle_company_addr1('','','Y',''); }else if(li1 == 15){ addEle_company_addr2('','','Y',''); }
}
function addEle_company_addr1(addr,name,pub,website){
	if(pub=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'"; }
	var build_name=$("#cu_cbuild1").html();	
	if(name==0){ build_name=$("#cu_cbuild_none").html(); }
	var radio="<input type='radio' name='cu_cpubl1' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_cpubl1' value='N' "+check2+" />N";
	var select="<select name='cu_cate1'><option>請選擇</option></select>";
	$("#company_addr").append("<li id='15'><input type='text' name='cu_cadd1' id='cu_cadd1' value='"+addr+"' class='large_input' onClick=showFamilyAddress('cu_cadd1') /><a onclick='removeEle_company_addr(15)' class='deleteitem'><i class='icon-trash'></i></a></a></li>");
	$("#building_company_name").append("<li class='15'><select name='cu_cbuild1' class='full_select' >"+build_name+"</select></li>");
	$("#per_com").append("<li class='15'>"+radio+"</li>");
	$("#company_website").append("<li class='15'><input type='text' name='cu_web1' class='com_website' id='cu_web1' value='"+website+"' /><input type='button' value='開啟IE' onclick=open_new_window('cu_web1'); /></li>");
}
function addEle_company_addr2(addr,name,pub,website){
	if(pub=="Y"){ var check1="checked='checked'"; }else{ var check2="checked='checked'"; }
	var build_name=$("#cu_cbuild2").html();	
	if(name==0){ build_name=$("#cu_cbuild_none").html(); }
	var radio="<input type='radio' name='cu_cpubl2' value='Y' "+check1+" />Y&nbsp;&nbsp;<input type='radio' name='cu_cpubl2' value='N' "+check2+" />N";
	var select="<select name='cu_cate2'><option>請選擇</option></select>";
	$("#company_addr").append("<li id='16'><input type='text' name='cu_cadd2' id='cu_cadd2' value='"+addr+"' class='large_input' onClick=showFamilyAddress('cu_cadd2') /><a onclick='removeEle_company_addr(16)' class='deleteitem'><i class='icon-trash'></i></a></a></li>");
	$("#building_company_name").append("<li class='16'><select name='cu_cbuild2' class='full_select' >"+build_name+"</select></li>");
	$("#per_com").append("<li class='16'>"+radio+"</li>");
	$("#company_website").append("<li class='16'><input type='text' name='cu_web2' class='com_website' id='cu_web2' value='"+website+"' /><input type='button' value='開啟IE' onclick=open_new_window('cu_web2'); /></li>");
}
function removeEle_company_addr(item){
	$("#"+item).remove();
	$("."+item).remove();
}
//company_addr end

//平日连络start
function checkWeek(num,week,start,end){
	if(week!='' && week!=null){ 
		if(num == 1){ addping1(week,start,end); }
		if(num == 2){ addping2(week,start,end); }
	}
}
function addping(){
	var li1 = $('#17').attr('id');
	var li2 = $('#18').attr('id');	
	var li=$('#ping li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 17){ addping1('','',''); }else if(li1 == 17){ addping2('','',''); }
}
function addping1(week,start,end){
	var week_html = $('#cu_week1').html();
	if(week==0){ week_html=$("#cu_week_none").html(); }
	var str_sm = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;起&nbsp;<input type='text' name='cu_week_start1' value='"+start+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	str_sm += "&nbsp;&nbsp;&nbsp;&nbsp;止&nbsp;<input type='text' name='cu_week_end1' value='"+end+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	$("#ping").append("<li id='17' class='ping_li'><select name='cu_week1' style='width:70px'>"+week_html+"</select>"+str_sm+"&nbsp;<a onclick='removeping(17)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function addping2(week,start,end){
	var week_html = $('#cu_week2').html();
	if(week==0){ week_html=$("#cu_week_none").html(); }
	var str_sm = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;起&nbsp;<input type='text' name='cu_week_start2' value='"+start+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	str_sm += "&nbsp;&nbsp;&nbsp;&nbsp;止&nbsp;<input type='text' name='cu_week_end2' value='"+end+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	$("#ping").append("<li id='18' class='ping_li'><select name='cu_week2' style='width:70px'>"+week_html+"</select>"+str_sm+"&nbsp;<a onclick='removeping(18)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function removeping(item){
	$("#"+item).remove();
}
//平日连络end

//假日連絡start
function checkHoli(num,holi,start,end){
	if(holi!='' && holi!=null){
		if(num == 1){ addholiday1(holi,start,end); }
		if(num == 2){ addholiday2(holi,start,end); }
	}
}
function addholiday(){
	var li1 = $('#19').attr('id');
	var li2 = $('#20').attr('id');
	var li=$('#holiday li').length;
	if(li==3){ alert("最多只能添加3個哦"); return; }
	if(li1 != 19){ addholiday1('','',''); }else if(li1 == 19){ addholiday2('','',''); }
}
function addholiday1(holi,start,end){
	var holi_html = $('#cu_holi1').html();
	if(holi==0){ holi_html = $("#cu_holi_none").html(); }
	var str_sm = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;起&nbsp;<input type='text' name='cu_holi_start1' value='"+start+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	str_sm += "&nbsp;&nbsp;&nbsp;&nbsp;止&nbsp;<input type='text' name='cu_holi_end1' value='"+end+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	$("#holiday").append("<li id='19' class='holiday_li'><select name='cu_holi1' style='width:70px;'>"+holi_html+"</select>"+str_sm+"&nbsp;<a onclick='removeholiday(19)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function addholiday2(holi,start,end){
	var holi_html = $('#cu_holi2').html();
	if(holi==0){ holi_html = $("#cu_holi_none").html(); }
	var str_sm = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;起&nbsp;<input type='text' name='cu_holi_start2' value='"+start+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	str_sm += "&nbsp;&nbsp;&nbsp;&nbsp;止&nbsp;<input type='text' name='cu_holi_end2' value='"+end+"' class='Wdate' onFocus=\"WdatePicker({dateFmt:'HH:mm'})\" style='width:70px;' />";
	$("#holiday").append("<li id='20' class='holiday_li'><select name='cu_holi2' style='width:70px;'>"+holi_html+"</select>"+str_sm+"&nbsp;<a onclick='removeholiday(20)' class='deleteitem'><i class='icon-trash'></i></a></li>");
}
function removeholiday(item){
	$("#"+item).remove();
}
//假日連絡end

function open_new_window(id){
	var url=$("#"+id).val();
	if(url!=''){
		var regexp=/.*https?:\/\/*/;
		if(regexp.test(url)){
			window.open(url,"newwindow","resizable=yes,location=no");
		}else{
			var regexp=/www\..*/;
			if(regexp.test(url)){
				window.open('http://'+url,"newwindow","resizable=yes,location=no");
			}else{
				alert("網址必須以www開頭");
			}			
		}
	}else{
		alert("網址不能為空");
	}
}

function open_email(id){
	var email=$('#'+id).val();
	if(email==''||email==undefined){
		alert('email不能為空');
	}else{
		var regexp=/.*@.*\..*/;
		if(regexp.test(email)){
			location.href='mailto:'+email;
		}else{
			alert('email格式輸入錯誤');
		}
	}
}